package com.caogt.user.userInfo.controller;

import com.caogt.common.restful.ResultData;
import com.caogt.user.userInfo.service.IUserInfoService;
import com.caogt.user.userInfo.entity.UserInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Desc 供其他服务接口调用
 * @user caogt
 * @Date 2019-06-15-10:37
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserInfoService userInfoService;

    @GetMapping("/userid/{id}")
    public ResultData<UserInfo> getUser(@PathVariable Long id) {
        if (id == null) return ResultData.fail("参数为空");
        UserInfo userInfo = userInfoService.getById(id);
        return ResultData.success(userInfo);
    }

    @GetMapping("/orgid/{id}")
    public ResultData getUserByOrgId(@PathVariable Long id) {
        if (id == null) return ResultData.fail("参数为空");
        return ResultData.success(userInfoService.getUserByOrgId(id));
    }

    @PostMapping("/validatePassword")
    public ResultData validatePassword(@RequestBody UserInfo userInfo) {
        if (userInfo == null || StringUtils.isBlank(userInfo.getLoginName())
                || StringUtils.isBlank(userInfo.getPassword())) {
            return ResultData.fail("参数为空");
        }
        boolean rest = userInfoService.validatePassword(userInfo.getLoginName(),userInfo.getPassword());
        ResultData resultData = new ResultData();
        resultData.setFlag(rest);
        return resultData;
    }
}
